package design.simdi.code.final_paper.site.panels.blog.trimise;

import java.util.ArrayList;
import java.util.List;

import org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn;
import org.apache.wicket.extensions.markup.html.repeater.data.table.PropertyColumn;
import org.apache.wicket.injection.web.InjectorHolder;
import org.apache.wicket.model.ResourceModel;
import org.hibernate.criterion.Restrictions;

import design.simdi.code.final_paper.core.entities.Mesaj;
import design.simdi.code.final_paper.site.application.WicketApplication;
import design.simdi.code.final_paper.site.panels.PagePanel;
import design.simdi.code.final_paper.site.panels.blog.SortableMesajDataProvider;
import design.simdi.code.final_paper.utils.ActionToolbar;
import design.simdi.code.final_paper.utils.MyDataTable;

/**
 * 
 * @author Marius Dumitriu - (Jun 25, 2010 - 11:24:07 PM)
 * 
 */
public class MesajeTrimiseTabPanel extends PagePanel {

	private static final long serialVersionUID = 1L;

	public MesajeTrimiseTabPanel(String id) {
		super(id);
		InjectorHolder.getInjector().inject(this);
		((WicketApplication) getApplication()).setShowErrors(true);
	}

	@Override
	public void panelInit() {
		List<IColumn<Mesaj>> columns = new ArrayList<IColumn<Mesaj>>();

		columns.add(new PropertyColumn<Mesaj>(new ResourceModel("subject"), "title", "title"));
		columns.add(new PropertyColumn<Mesaj>(new ResourceModel("date"), "date", "date"));
		columns.add(new PropertyColumn<Mesaj>(new ResourceModel("destinatar"), "destinatar"));
		columns.add(new PropertyColumn<Mesaj>(new ResourceModel("status"), "status", "status"));

		SortableMesajDataProvider sortablMesajPrimitDataProvider = new SortableMesajDataProvider();
		sortablMesajPrimitDataProvider.getCriterii().add(Restrictions.eq("expeditor.id", getCurrentPerson().getId()));
		add(new MyDataTable<Mesaj>("table", columns, sortablMesajPrimitDataProvider, getRowsPerPage()) {

			private static final long serialVersionUID = 1L;

			@Override
			public ActionToolbar getActionToolbar() {
				return new MesajTrimisActionToolbar(this);
			}
		});
	}
}
